<?php
/****
	测试使用文件，队列执行文件
***/
	header('content-type:text/html;charset=utf-8');	
	ini_set('date.timezone','Asia/Shanghai');
	
	require_once $_SITE_PATH_ . "m/m_information.php";
	require_once $_SITE_PATH_ . "m/m_agreement.php";
	require_once $_SITE_PATH_ . "m/m_tasklist.php";
	require_once $_SITE_PATH_ . "m/m_taskerror.php";
	require_once $_SITE_PATH_ .'backend\apis\Queue_Class.php';
	require_once $_SITE_PATH_ .'backend\apis\UpFile_ApiClient.class.php';
	
	$upfile_flag=isset($_POST['upfile_flag'])?$_POST['upfile_flag']:'';
	
	
	$m_agreement=new m_agreement();
	$m_information=new m_information();
	$m_tasklist=new m_tasklist();
	$m_taskerror=new m_taskerror();
	$queue=new QueueClass();
	
	
	
	$m_tasklist->_ssql='select `id`,`product_id` from tasklist where ts_type="1" and excuflag="0" and ts_flag="0" order by `id` asc limit 0,15 ';//asc limit 0,1 
	$product_id=$m_tasklist->getArray($m_tasklist->query());
	$count=$m_tasklist->getCount(' ts_type="1" and excuflag="0" and ts_flag="0" ');
	$code='';
	$code_str='';
	
	
	if($count<=0)
		{
			exit;
		}
		else
			{
				for($i=0;$i<$count;$i++)
					{
						$code=json_decode(trim($product_id[$i]->product_id,chr(231).chr(187).chr(191)),true);//解压JSON数据
						$order_sn='';
						for($j=0;$j<count($code);$j++)
							{
								//$code_str.=','.$code['code'];
								$order_sn=$code['order_sn'];
							}
							
							foreach($code as $key => $value)
											{
												if(strtolower($key)=='fileinfo')
													{
														$vcount=count($value);
														for($index=0;$index<$vcount;$index++)
															{
																$code_str.=','.$value[$i]['code'];
															}
													}
											}
										$code_str=trim($code_str,',');
										$code_str=number_format($code_str,'','','');
										$product_id[$i]->code=$code_str;
										$product_id[$i]->order_sn=$order_sn;
										$queue->add_item($product_id[$i]->code);
							//echo $code_str;
							//echo '<br/>';
						/* $code_str=trim($code_str,',');
						$product_id[$i]['code']=$code_str;
						$product_id[$i]['order_sn']=$order_sn;
						
						$queue->additem($product_id[$i]['code']); */
					}
				
				
				for($i=0;$i<$count;$i++)
					{
						$code=$queue->del_item();
						echo $code;
						$api=new UpFile_ApiClient();
						$data=array('code'=>$code,'order_sn'=>$product_id[$i]->order_sn,'taskid'=>$product_id[$i]->id,'apiflag'=>'1','flag'=>'coprsys','method'=>'copr.update','type'=>'json','timestamp'=>time(),'charset'=>'utf-8','ver'=>1,'file_status'=>'');
						$url='http://localhost/index.php?a=apis.FileFlag_Client';
						//重新用计划任务执行指定次数的推送数据任务。
						$result=$api->DoRequest($url,$auth,$data);
						var_dump($result);
						usleep(100);
						 
						
					}
			}
	
	
	//整合ID值
			
			
	/* $upfile=array(
		array('code'=>'12345646',
			'is_upfile'=>'1',
			'order_sn'=>'123456789',
			'order_address'=>'safsdafasdf'),
		array('code'=>'45612345646',
			'is_upfile'=>'1',
			'order_sn'=>'123456',
			'order_address'=>'safsdafasdf'),
		array('code'=>'12345646',
			'is_upfile'=>'1',
			'order_sn'=>'123456',
			'order_address'=>'safsdafasdf')			
		);
	$count=3; */
	
	
	$auth='tjiePjfjvnyGUuyMFEXVPmsewokCauuZ';
	$json_arr=array('data'=>$upfile,'count'=>$count);
	$json_arr=json_encode($json_arr);
	echo $json_arr;
	//exit;
	$time=time();
	$data=array('flag'=>'coprsys','method'=>'copr.update','type'=>'json','timestamp'=>$time,'charset'=>'utf-8','ver'=>1,'file_status'=>$json_arr);
	$url='http://120.86.185.197/index.php/openapi/rpc/service';
	$api=new UpFile_ApiClient();
	$result=$api->DoRequest($url,$auth,$data);
	var_dump($result);
	exit;
	if(strtoupper($result['info'])=='SUCCESS')
		{
			/* $m_tasklist->_ssql='update tasklist set `ts_flag`="1",excuflag="1" where `id`='.$product_id[0]->id;
			$m_tasklist->query(); */
			//写入日志 fopen();
			exit;
		}
		elseif(strtoupper($result['info'])=='FAILED')
			{
				exit;
			}
			else
				{
					exit;
				}


















	


?>